<?php
require_once 'models/models_binhluan.php';
$obbl=new models_binhluan();
require_once 'models/models_user.php';
$obus=new models_user();
$mod=$_GET['mod'];
switch ($mod)
{
	case 'listbinhluan':{
		
		$obbl->_getbinhluan($_GET['id']);
		require_once 'views/main/binhluan/binhluan.php';
		break;
	}
	case 'addcom':
			{
			
				$a=$_GET['id'];
				if(isset($_SESSION['username'])){
				$user=$obus->getusers($_SESSION['username']);	
				if($_POST)
				{
					if(isset($_POST['txtCaptcha']))
					{
					if($_POST['txtCaptcha'] == $_SESSION['security_code'])
					{
						$obbl->addbinhluan($_GET['id'],$user['HoTen'],$user['DienThoai'],$user['Email'],gmdate("Y-m-d H:i:s", time()+7*3600),$_POST['noidung']);
						echo '<script>window.location.href="index.php?mod=binhluanthanhcong"</script>';
					}
					}else{
						echo '<script>window.location.href="index.php?mod=addcom&id='.$a.'</script>';
					}
					
				}
					
				}else {
					
				
				
				if($_POST)
				{
					if(isset($_POST['txtCaptcha']))
					{
					if($_POST['txtCaptcha'] == $_SESSION['security_code'])
					{
						$obbl->addbinhluan($_GET['id'],$_POST['hoten'],$_POST['dienthoai'],$_POST['txtmail'],gmdate("Y-m-d H:i:s", time()+7*3600),$_POST['noidung']);
						echo '<script>window.location.href="index.php?mod=binhluanthanhcong"</script>';
					}
					}else{
						echo '<script>window.location.href="index.php?mod=addcom&id='.$a.'</script>';
					}
					
				}}
				
				require_once 'views/main/binhluan/binhluan.php';
				break;
			}
		case 'binhluanthanhcong':{
			
			require_once 'views/main/binhluan/binhluanthanhcong.php';
			break;
		}
}